package com.xq.shop.service.user.impl;

import java.util.ArrayList;
import java.util.List;

import com.xq.shop.service.user.IBaseService;
import com.xq.shop.vo.PageInfo;
import com.xq.shop.vo.SearchObject;

public abstract class  BaseService<T> implements IBaseService<T> {

	@Override
	public List<T> get(List<Long> ids) {
		return getDAO().get(ids.toArray(new Long[0]));
	}

	@Override
	public T get(Long id) {
		return getDAO().get(id);
	}

	@Override
	public List<T> get(Long[] ids) {
		return getDAO().get(ids);
	}

	@Override
	public PageInfo<T> get(SearchObject search) {
		
		long total = 0;
		
		
		List<T> result = new ArrayList<T>();
		total = getDAO().getCount(search);
		result = getDAO().get(search);
		
		return new PageInfo<T>(search, result, total);
	}

	@Override
	public void save(T instance) {
		getDAO().save(instance);
	}

	@Override
	public void update(T instance) {
		getDAO().update(instance);
	}

	@Override
	public void saveOrUpdate(T instance) {
		getDAO().saveOrUpdate(instance);
	}
	
	public void saveOrUpdate(List<T> list){
		getDAO().saveOrUpdateAll(list);
	}
	

	@Override
	public void delete(List<Long> ids) {
		getDAO().delete(ids);
	}
}
